package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.ExportDao;
import cn.itcast.dao.cargo.PackingDao;
import cn.itcast.domain.cargo.Export;
import cn.itcast.domain.cargo.ExportExample;
import cn.itcast.domain.cargo.Packing;
import cn.itcast.domain.cargo.PackingExample;
import cn.itcast.service.cargo.PackingService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

@Service(timeout = 100000)
public class PackingServiceImpl implements PackingService{
    @Autowired
    private PackingDao packingDao;
    @Autowired
    private ExportDao exportDao;

    @Override
    public Packing findById(String id) {
        return packingDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Packing> findAll(PackingExample packingExample) {
        return packingDao.selectByExample(packingExample);
    }

    @Override
    public void save(Packing packing) {
        //设置id唯一值
        packing.setPackingId(UUID.randomUUID().toString());
        //设置状态为0
        packing.setState(0);

        packingDao.insertSelective(packing);
    }

    @Override
    public void update(Packing packing) {
        packingDao.updateByPrimaryKeySelective(packing);
    }

    @Override
    public void delete(String id) {
        packingDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo(packingDao.findAll());
    }


}
